using System;
using System.Collections.Generic;
using System.Text;

namespace Pitoshka.Tools.ResourceFilesChecker
{
	class Program
	{
		private static string _RootPath;
		public static string RootPath
		{
			get { return _RootPath; }
			set { _RootPath = value; }
		}

		public static string[] AllowedExtensions = new string[] { "aspx", "ascx" };

		private static List<String> _Cultures = new List<string>();
		public static List<String> Cultures
		{
			get { return _Cultures; }
			set { _Cultures = value; }
		}


		static void Main(string[] args)
		{
			Cultures.Add("da");

			if (args.Length > 0)
				RootPath = args[0];

			try
			{
				ResDirectory rd = new ResDirectory(RootPath);
				rd.Load();
				
				rd.Check();
				Check(rd);

				rd.FixErrors();

				rd.Check();
				Check(rd);
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.ToString());
			}
			finally
			{
				Console.ReadKey();
			}
		}

		private static void Check(ResDirectory dir)
		{
			Console.WriteLine(dir.ResDirectoryPath.Replace(RootPath, @".."));
			foreach (ResourceFile file in dir.ResourceFiles)
			{
				foreach (KeyValuePair<string, List<KeyValuePair<EnumErrorType, string>>> locFile in file.Errors)
				{
					if (locFile.Value.Count > 0)
					{
						Console.WriteLine();
						Console.WriteLine(locFile.Key.Replace(RootPath, ""));
					}

					foreach (KeyValuePair<EnumErrorType, string> error in locFile.Value)
					{
						Console.WriteLine(error.Value);
					}
				}
			}
			foreach (ResDirectory child in dir.Children)
			{
				Check(child);
			}
		}
	}
}
